<template>
    <div>
        <h2>房号添加</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>房型名称</td>
                    <td>
                        <input type="text" v-model="model.HouseTypeName">
                    </td>
                </tr>


                <tr>
                    <td>房号名称</td>
                    <td>
                        <input type="text" v-model="model.HouseNoName">
                    </td>
                </tr>


                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="status" value="1" v-model="model.State">上架
                        <input type="radio" name="status" value="2" v-model="model.State">下架
                    </td>
                </tr>



                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-success" @click="ok">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import axios from 'axios'
const router = useRouter()
const route = useRoute()

let model = reactive({

    "HouseTypeName": '',
    "HouseNoName": '',
    "State": 1,

})


//添加
const ok = () => {
    
axios({
url: 'https://localhost:7154/api/HouseNo/HouseNoAdd',
method: 'post',
data: model,
})
.then(res => {
    console.log(res);
    if(res.data==-1){
        alert('该房号已存在')
        return;
    }
    else if(res.data==1){
        alert('添加成功')
        router.push('/houseNoList')
    }
    else{
        alert('添加失败')
    }


})

.catch(err => {
    console.log(err);
})






}



</script>

<style scoped></style>